/**
 * Created by AllanXu on 01/03/2016.
 */
define(function (require) {
	var Vue = require('vue'),
        Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities'),
        userId = sessionStorage.id;

	var typeId = utilities.getParameterByName('typeId');
    var id = utilities.getParameterByName('id');
    if (typeof userId == 'undefined' || userId == ''){
        if (typeof id == 'undefined' || id == ''){
            location.href ="http://qqlian.org/wxOAuth?appId=wxd69e1b0ea689bf23&callBackUrl=activity_detail.html?typeId="+typeId;
        }else{
            sessionStorage.setItem('id', id);
            location.href = 'activity_detail.html?typeId='+typeId;
        }
    }
    //console.log(utilities);
	// 认证
    var AuthDialog = require('auth_dialog');
    var authDialog = new AuthDialog();
    // 禁用申诉
    var Forbidden = require('forbidden');
    var forbidden = new Forbidden();

	var app = new Vue({
		el: '#activity_detail',
		data: {
		    thumb: true,
		    mainInfo: '',
            applied: [],
            showFlag: false,
            rowCount: '',
			picServer: Config.picServer
		},
		methods:{
			init: function () {
                _(Config.SERVICE.ACTIVITY.DETAILS+'?id='+typeId+'&part.member.id='+userId, {}, function(data) {
                    //console.log(data);
                    app.mainInfo = data.obj;
                });
                
                _(Config.SERVICE.ACTIVITY.APPLIEDS+'?blind.id='+typeId+'&type=3', {}, function(data) {
                    //console.log(data,23);
                    //app.applied = data.obj;
                    app.applied = data.pageitems;
                    app.rowCount = data.rowcount;
					// app.mainInfo = data.obj;
                });
                utilities.refreshUserInfo(function (data) {
                    // app.renderObj = data;
                });
			},
			apply: function () {
                var userInfo = JSON.parse(decodeURIComponent(atob(sessionStorage.userInfo)));
                if (userInfo.member.sfgb == 1) {	// 认证
                    if (confirm("您已脱单，如需继续使用，请点击恢复单身。")) {
                        location.href = 'uc_index.html';
                    }
                    return;
                }
				// 是否认证/禁用
                // base64TojsonObj
                /*var userInfo = JSON.parse(decodeURIComponent(atob(sessionStorage.userInfo)));
                if(userInfo.member.sfrz==0){	// 认证
                	authDialog.show();
                }else{
                	// 已认证、没有禁用

                    _(Config.SERVICE.MATES.VERIFY+'?id=' + userId, {}, function(data) {
                        if(data.errmsg.indexOf("择偶") > 0 ){
                            // 择偶条件没有完善跳转到择偶条件
                             if(confirm("为更好地为您提供服务，请在“个人编辑”中完善择偶条件。")){
                                location.href = 'uc_mate_condition.html';
                             }
                        }else if(data.errmsg.indexOf("基本信息") > 0){
                            if(confirm("为更好地为您提供服务，请在“个人编辑”中完善个人资料。")){
                                location.href = 'uc_profile.html';
                             }
                        }else if(data.errmsg.indexOf("形象照") > 0){
                            if(confirm("为更好地为您提供服务，请在“个人编辑”中上传形象照。")){
                                location.href = 'uc_basicInfo.html';
                            }
                        }else{*/
                            _(Config.SERVICE.ACTIVITY.APPLY+'?part.blind.id='+typeId+'&part.member.id='+userId, {}, function(data) {
                                console.log(data);
                                if(data.code==200){
                                    alert("报名成功！");
                                    app.mainInfo.isPart='1';
                                }
                            });
                       /* }
                    });
                	
                }*/
            },
            isShow: function(){
                app.showFlag = !app.showFlag;
            },
			cancelApply: function () {
            	_(Config.SERVICE.ACTIVITY.CANCELAPPLY+'?xgmember.id='+userId+'&blind.id='+typeId, {}, function(data) {
                	console.log(data);
                    if(data.code==200){
                    	alert("取消报名成功！");
                    	app.mainInfo.isPart='0';
					}
                });
            },
            goDetail: function(id){
                window.location.href = "friend_detail.html?id=" +id;
            },
            goDetailQd: function(id){
                window.location.href = "uc_activeRank.html?id=" +id;
            },
		}
	});
	app.init();
});
